package com.binge.backend.service.impl;

import com.binge.backend.dao.CartMapper;
import com.binge.backend.entity.BookEntity;
import com.binge.backend.entity.CartEntity;
import com.binge.backend.service.ICartService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author binge
 * @Description 购物车业务逻辑实现类
 * @date 2023年10月01日 下午 9:14
 */
@Service
@Slf4j
@Transactional
public class CartServiceImpl implements ICartService {
    @Resource
    private CartMapper cartMapper;

    @Override
    public List<CartEntity> getCart(String username,int pageNum) {
        return null;
    }

    @Override
    public int deleteBook(int id) {
        int result = cartMapper.deleteUserShopCarBook(id);
        return result;
    }

    @Override
    public int getTotal(String username) {
        int totalPrice = 0;
        List<CartEntity> cartEntities = cartMapper.getUserCart(username);
        for (CartEntity cart : cartEntities) {
            totalPrice += cart.getBookNum() * cart.getPrice();
        }
        return totalPrice;
    }
}
